#include "socket.h"

#include "netlib.h"

namespace kxlua {

Socket::Socket(NetLib* lib) {
    lib_ = lib;
    name_ = "Socket";
    isOpen_ = false;
}

Socket::~Socket() {
}

const std::string& Socket::GetName() const {
    return name_;
}

bool Socket::Open() {
    if (!isOpen_) {
        luabind::module(lib_->GetLua().GetState()) 
        [
            luabind::def("CreateSocket", (net::ISocket*(*)())&net::GetSocket),

            luabind::class_<net::ISocket>("Socket")
            .def("Send", &net::ISocket::Send)
            .def("Close", &net::ISocket::Close)
            .def("SetHandler", &net::ISocket::SetHandler)
            .def("GetInBuffer", &net::ISocket::GetInBuffer)
            .def("GetOutBuffer", &net::ISocket::GetOutBuffer)
            .def("Connect", &net::ISocket::Connect)
        ];
        isOpen_ = true;
    }
    return true;
}

bool Socket::Close() {
}

}
